﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;
using Runda.CMS.Common.Utility;

namespace Runda.CMS.Portal.SysManage
{
    public partial class LogList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindLogList(1);
            }
        }
        private void BindLogList(int pageindex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            int RecordCount = 0;
            List<SysLogEntity> list = new SysLogBll().GetAll<SysLogEntity>(parms, "CreatedOn desc", AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterLogs.DataSource = list;
            RepeaterLogs.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void RepeaterLogs_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindLogList(1);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

            BindLogList(AspNetPager1.CurrentPageIndex);
        }

        protected void RepeaterLogs_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Label lblOperator = e.Item.FindControl("lblOperator") as Label;
                Label lblEmployeeName = e.Item.FindControl("lblEmployeeName") as Label;

                if (lblOperator != null && lblOperator.Text.Trim() != "")
                {
                    SysUserEntity entity = new SysUserBll().Get<SysUserEntity>(new Guid(lblOperator.Text.Trim()));
                    if (entity != null)
                    {
                        lblEmployeeName.Text = entity.UserName;
                    }
                    else
                    {
                        lblEmployeeName.Text = "系统";
                    }
                }
            }
        }
    }
}
